<template>
    <div>
        <van-picker title="更新性别" :default-index="gender" show-toolbar :columns="columns" @confirm="onConfirm"
            @cancel="onCancel" />
    </div>
</template>

<script>
import { aditUserProfileAPI } from '@/api'
export default {
    props: {
        gender: {
            type: [String, Number],
            required: true
        }
    },
    data() {
        return {
            columns: ['男', '女']
        }
    },
    methods: {
        async onConfirm(val, index) {
            try {
                await aditUserProfileAPI({
                    gender: index
                })
                this.$emit('updata:gender', index)
                this.$emit('close')
                this.$toast.success('修改性别成功')
            } catch (error) {
                this.$toast.fail('修改性别失败')
            }
        },
        onCancel() {
            this.$emit('close')
        }
    }
}
</script>

<style>

</style>